<template>
	<view class="nameedit" :data-theme="theme" :class="theme" :style="globalColor.style">
		<HeadCustom></HeadCustom>
		<view>
			<view class="pad_top40">
				<view class="addressBox" v-if="grxxData.id == 'addressInfo'" @click="goSelectMap">{{ nameValue }}</view>
				<u--input
					v-else
					:type="grxxData.id == 'mobile' ? 'number' : 'text'"
					class="ipt_box"
					placeholder="请输入内容"
					clearable
					:maxlength="grxxData.id == 'mobile' ? 11 : -1"
					border="surround"
					v-model="nameValue"
					@change="change"
				></u--input>
			</view>
			<view class="pad_top40" style="color: #6B707C;font-size: 22rpx">{{ desObj[grxxData.id] }}</view>
			<view class="public_box">
				<text>是否对陌生人公开</text>
				<u-switch v-model="ispublic" size="23" activeColor="#CC9870" inactiveColor="#E8EDF1" @change="changePublic"></u-switch>
			</view>
		</view>
		<BottomBtn title="保存" @btnClick="clickBtn"></BottomBtn>
	</view>
</template>

<script>
import BottomBtn from '@/components/bottom-btn/index.vue';
import { putCardUpdate } from '@/api/card.js';
export default {
	components: { BottomBtn },
	props: {},
	data() {
		return {
			theme: getApp().globalData.appTheme,
			globalColor: getApp().globalData.globalColor,
			detail: getApp().globalData.cardTemp,
			nameValue: '',
			ispublic: false,
			grxxData: {},
			desObj: {
				mobile: '请输入自己的手机号码。',
				email: '请输入自己的邮箱地址。',
				addressInfo: '请设置自己真实所在地址。'
			}
		};
	},
	onLoad(data) {
		this.grxxData = data;
		this.nameValue = this.detail[this.grxxData.id];
		if (this.grxxData.id !== 'addressInfo') {
			this.ispublic = this.detail[this.grxxData.id + 'Open'];
		} else {
			this.ispublic = this.detail.addressOpen;
			// #ifdef H5
			const addresObj = getApp().globalData.recruitmentTemp;
			if (Object.keys(addresObj).length != 0) {
				this.nameValue = addresObj.workAddress;
			} else {
				// this.nameValue = this.detail[this.grxxData.id];
			}
			// #endif
		}
		// #ifdef H5
		uni.setNavigationBarTitle({
			title: `${this.grxxData.type}`
		});
		// #endif
	},
	methods: {
		goSelectMap() {
			// 授权并获取当前位置
			const _this = this;
			// #ifdef H5
			this.$pageTo('/bwSign/map');
			// #endif

			// #ifdef MP
			uni.getLocation({
				success: res => {
					uni.chooseLocation({
						latitude: res.latitude,
						longitude: res.longitude,
						success: data => {
							_this.detail.latitude = data.latitude;
							_this.detail.longitude = data.longitude;
							_this.nameValue = data.name;
						}
					});
				}
			});
			// uni.authorize({
			// 	scope: 'scope.userLocation',
			// 	success: () => {
			// 		console.log('成功1号');
					
			// 	}
			// });
			// #endif
		},
		change() {
			// console.log(1111);
		},
		// 保存
		clickBtn() {
			getApp().globalData.recruitmentTemp = {};
			this.detail[this.grxxData.id] = this.nameValue;
			putCardUpdate({ ...this.detail }).then(res => {
				if (res.data) {
					uni.navigateBack();
				}
			});
		},
		// 是否公开
		changePublic(data) {
			if (this.grxxData.id !== 'addressInfo') {
				this.detail[this.grxxData.id + 'Open'] = this.ispublic;
			} else {
				this.detail.addressOpen = this.ispublic;
			}
		}
	}
};
</script>

<style lang="scss" scoped>
::v-deep .uni-input-input {
	color: var(--contentFontDarkColor);
}
::v-deep .u-switch__node {
	background-color: var(--contentFontFiveColor);
}
::v-deep .u-switch__node--on {
	background-color: var(--viewBgColor);
}
.nameedit {
	height: 100vh;
	padding: 0 40rpx;
	.pad_top40 {
		padding-top: 40rpx;
		.addressBox {
			background-color: var(--viewBgColor);
			padding: 15rpx 20rpx;
			border-radius: 8rpx;
			line-height: 44rpx;
			font-size: 30rpx;
			min-height: 70rpx;
		}
	}
	.public_box {
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: var(--viewBgColor);
		margin-top: 40rpx;
		padding: 0 20rpx;
		color: var(--contentFontDarkColor);
		border-radius: 8rpx;
	}
}
.nameedit ::v-deep  .u-input {
	background-color: var(--viewBgColor);
	border: none;
}
</style>
